package com.preguicoso.client.telaInicial;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.event.logical.shared.AttachEvent;

public class lightBox extends Composite  {

	private static lightBoxUiBinder uiBinder = GWT
			.create(lightBoxUiBinder.class);
	@UiField Button close;
	@UiField HTMLPanel overlay;
	@UiField HTMLPanel lightbox;
	@UiField HTMLPanel caixa;
	@UiField HTMLPanel panel;
	
	int size=300;
	int height=300;

	interface lightBoxUiBinder extends UiBinder<Widget, lightBox> {
	}
	private static lightBox instance = null;
	public static lightBox getInstance() {
		if (instance == null) {
		
				instance = new lightBox();
		}
		return instance;
	}
	
	private lightBox() {
		initWidget(uiBinder.createAndBindUi(this));
		panel.setVisible(false);
		RootPanel.get("lightbox").add(this);
	}
	
	public void show(Widget ui,int width,int height){
		caixa.clear();
		if(Window.getClientWidth()<500){
			RootPanel.get("content").setVisible(false);
			caixa.setWidth("84%");
			caixa.setHeight("100%");
			caixa.add(close);
			caixa.add(ui);
			RootPanel.get("lightbox").addStyleName("iphoneLightbox");
		}else{
			caixa.setWidth(width+"px");
			caixa.setHeight(height+"px");
			caixa.add(close);
			caixa.add(ui);
		}
		panel.setVisible(true);
	}
	public void show(Widget ui,String width,String height){
		caixa.clear();
		if(Window.getClientWidth()<500){
			RootPanel.get("content").setVisible(false);
			caixa.setWidth("84%");
			caixa.setHeight("100%");
			caixa.add(close);
			caixa.add(ui);
			RootPanel.get("lightbox").addStyleName("iphoneLightbox");
			
		}else{
			caixa.setWidth(width);
			caixa.setHeight(height);
			caixa.add(close);
			caixa.add(ui);
		}
			panel.setVisible(true);	
	}
	public void hide(){
		RootPanel.get("content").setVisible(true);
		panel.setVisible(false);
		RootPanel.get("content").setVisible(true);
	}
	
	public void showLoading(String text){
		lightBox.getInstance().show(new HTMLPanel("<div style=\"text-align:center\"><img src=\"/img/ajax-loader.gif\"/><br/><h3>"+text+"</h3></div>"), 190, 60);
	}
	

	@UiHandler("close")
	void onCloseClick(ClickEvent event) {
		hide();
	}
}
